package com.ruoyi.controller.tourism;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.service.tourism.BudgetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zeo
 * @explain 上年同期月累计额和月度预算填写
 * @date 2021/2/1 10:33
 */
@Controller
@RequestMapping("/budget")
public class BudgetController extends BaseController {

    @Autowired
    BudgetService budgetService;

    private String prefix = "tourism/budget";

    @GetMapping("/add")
    public String add(String type, ModelMap mmap) {
        mmap.put("type", type);
        return prefix + "/add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map map) {
        return toAjax(budgetService.add(map));
    }

    @GetMapping("/edit/{id}")
    public String edit(ModelMap mmap, @PathVariable("id") String id, String type) {
        mmap.put("type", type);
        mmap.put("data", budgetService.findBudgetById(id));
        return prefix + "/edit";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(budgetService.edit(map));
    }
}
